<template>
	<sl-page :isDisplay="false">
		<view class="distribution">
			<!-- 头部 -->
			<view class="distribution-head">
				<view class="head-content">
					<view class="flex">
						<view class="content-profile">
							<view class="profile-headimg" v-if="distributionUser.image">
								<sl-image :value="distributionUser.image"></sl-image>
							</view>
							<view class="profile-avatar" v-else>
								<sl-image :value="avatar"></sl-image>
							</view>
						</view>
						<view class="flex flex-column m-l34">
							<view class="content-name">
								{{distributionUser.name}}
							</view>
							<view class="flex flex-y-center" @click="toTargetPage('xj_distribution/index/rules')">
								<view class="content-level">
									<sl-image :value="distributionUser.gradeImage"></sl-image>
								</view>
								<view class="px-l-1">
									{{distributionUser.gradeName}}
								</view>
								<uni-icons type="forward" size="16"></uni-icons>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="distribution-account">
				<view class="flex flex-x-between p-32">
					<view class="f-w">
						账户
					</view>
					<view class="f-w f-24 flex flex-y-center" @click="toTargetPage('xj_distribution/account/index')">
						<view class="">
							账户结算
						</view>
						<uni-icons type="forward" size="14"></uni-icons>
					</view>
				</view>
				<view class="flex flex-x-around">
					<view class="flex flex-dir-column flex-y-center" v-for="(item, index) in accountAnalyse"
						:key="index">
						<Money :priceValue="item.count" :activeClass="['money-36']"></Money>
						<view class="py-1 f-tip f-24">{{ item.name }}</view>
					</view>
				</view>
			</view>
			<!-- 会员卡 -->
			<view class="distribution-body">
				<view class="f-w p-32">
					业务入口
				</view>
				<view class="body-business">
					<view class="flex flex-x-between">
						<view class="business-customer" @click="toTargetPage('xj_distribution/invitation/customer')">
							<view class="">
								<view class="f-w">
									邀请顾客
								</view>
								<view class="f-24 py-1 f-tip">
									限时特惠
								</view>
							</view>
							<view class="customer-img">
							</view>
						</view>
						<view class="business-partner" @click="toTargetPage('xj_distribution/invitation/partner')">
							<view class="">
								<view class="f-w">
									招募合伙人
								</view>
								<view class="f-24 py-1 f-tip">
									加入推广
								</view>
							</view>
							<view class="partner-img">
							</view>
						</view>
					</view>
					<view class="business-goods">
						<view class="flex">
							<svg-icon id="distributionPs" name="distributionPs"></svg-icon>
							<svg-icon id="distributionMoney" name="distributionMoney"></svg-icon>
						</view>
						<view class="goods-promotion">
							商品推广
						</view>
						<view class="goods-brokerage">
							赚取佣金
						</view>
						<view class="goods-go" @click="toTargetPage('xj_distribution/goods/index')">
							GO
						</view>
					</view>
				</view>
				<!-- 星橘服务 -->
				<view class="body-data">
					<view class="data-head">
						<view class="f-w">数据看板</view>
					</view>
					<view class="data-menu">
						<view class="flex flex-column flex-y-center" @click="toTargetPage(item.url)"
							v-for="(item, index) in services" :key="index">
							<view class="iconfont" :class="item.icon"></view>
							<view class="py-1 f-tip f-24">{{ item.name }}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</sl-page>
</template>

<script>
	import DistributionApi from '@/api/distribution/distribution.js';
	import BalanceApi from '@/api/finance/balance.js';
	import Constants from '@/constants';
	import Money from '@/pages/components/money/money.vue';

	export default {
		name: 'distributionIndex',
		//
		mixins: [Constants],
		//
		components: {
			Money
		},
		//
		data() {
			return {
				//正在加载
				isLoading: true,
				//是否已登录
				isLogin: false,
				//分销用户
				distributionUser: {},
				user: {},
				//星橘服务
				services: [{
					id: '1',
					name: '商品订单',
					icon: 'icon-shangpindingdan',
					url: 'xj_distribution/order/index',
				}, {
					id: '2',
					name: '我的顾客',
					icon: 'icon-wodeguke',
					url: 'xj_distribution/customer/index',
				}, {
					id: '3',
					name: '我的合伙人',
					icon: 'icon-wodehehuoren',
					url: 'xj_distribution/partner/index',
				}, {
					id: '4',
					name: '经营分析',
					icon: 'icon-jingyingfenxi',
					url: 'xj_distribution/analysis/index',
				}],
				//账户分析
				accountAnalyse: [{
					id: '1',
					name: '待结算',
					count: 0,
				}, {
					id: '2',
					name: '可提现',
					count: 0,
				}, {
					id: '3',
					name: '冻结中',
					count: 0,
				}],
			};
		},
		//
		computed: {

		},
		//
		onLoad() {
			// this.initAccountMenu();
			// this.initServiceMenu();
		},
		//
		onShow() {
			this.onRefreshPage();
		},
		//
		methods: {
			//
			onRefreshPage() {
				//判断是否已登录
				// this.isLogin = !!this.$store.getters.token;
				//获取页面数据
				// if (this.isLogin) {
				this.getPageData();
				// }
			},
			//获取页面数据
			getPageData: async function() {
				const app = this;
				app.isLoading = true;
				//获取业务数据
				Promise.all([app.getDistributionUser(),app.getDistributionAccount()])
					.then(result => {
						//
						// this.nickname = result[0].name;
						// 初始化订单操作数据
						// app.initOrderTabbar();
						// app.initFFC();
						// 执行回调函数
						// callback && callback(); 
					})
					.catch(err => console.log('【获取页面数据数据失败】:', err))
					.finally(() => {
						app.isLoading = false;
					});
			},
			//得到分销人
			getDistributionUser: async function() {
				let res = await DistributionApi.get();
				console.log('res:--------------11x ',res);
				this.distributionUser = res.obj;
			},
			//得到分销账户统计
			getDistributionAccount: async function() {
				let res = await BalanceApi.get();
				console.log('res:-------------- ',res);
				// this.distributionUser = res.obj;
			},
			//跳转到我的相关
			toTargetPage(url) {
				// if (!this.isLogin) {
				// 	this.handleLogin();
				// } else {
					// const userId = this.$store.getters.user.id;
					this.$app.navTo(url);
				// }
			},
		}
	};
</script>

<style lang="scss" scoped>
	.distribution {
		font-size: $uni-font-size-base;
		color: $uni-text-color-primary;

		.distribution-head {
			position: absolute;
			top: 0;
			left: 0;
			right: 0;
			height: 546rpx;
			background-image: url("@/xj_distribution/static/distributionBackground.png");
			z-index: 1;

			.head-content {
				display: flex;
				justify-content: space-between;
				margin-top: 124rpx;
				margin-left: 46rpx;
				margin-right: 46rpx;

				.content-profile {
					position: relative;
					width: 104rpx;
					height: 104rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					border-radius: 10%;
					overflow: hidden;
					border: 2rpx solid #CCCCCC;
					background-color: #FFFFFF;

					.profile-headimg {
						position: relative;
						width: 104rpx;
						height: 104rpx;
					}

					.profile-avatar {
						position: relative;
						width: 72rpx;
						height: 60rpx;
						opacity: 0.3;
					}
				}

				.content-name {
					font-style: normal;
					font-weight: 600;
					font-size: 36rpx;
					line-height: 44rpx;
					color: #333333;
				}

				.content-level {
					margin-top: 6rpx;
					position: relative;
					width: 60rpx;
					height: 50rpx;
				}
			}
		}

		.distribution-account {
			position: relative;
			margin-top: 300rpx;
			display: flex;
			flex-direction: column;
			height: 127px;
			margin-left: 32rpx;
			margin-right: 32rpx;
			border-radius: 4px;
			background: #FFF;
			box-shadow: 0px 2px 9px 0px rgba(0, 0, 0, 0.06);
			// border: 1px solid red;
			z-index: 10;
		}

		.distribution-body {
			position: relative;
			margin-top: -16px;
			display: flex;
			flex-direction: column;
			// height: 576px;
			flex-shrink: 0;
			border-radius: 20rpx;
			z-index: 20;
			background-color: $uni-bg-color-grey;
			// border: 1px solid yellow;

			.body-business {
				margin-top: 24rpx;
				margin-left: 32rpx;
				margin-right: 32rpx;

				.business-customer {
					display: flex;
					width: 164px;
					height: 80px;
					flex-shrink: 0;
					border-radius: 4px;
					background: #FFF;
					box-shadow: 0px 2px 9px 0px rgba(0, 0, 0, 0.06);
					padding-top: 20px;
					padding-left: 16px;

					.customer-img {
						height: 108rpx;
						width: 108rpx;
						margin-left: 12px;

						border-radius: 100% 100% 100% 100%;
						background-image: url("@/xj_distribution/static/distributionCustomer.png");
						background-repeat: no-repeat;
						/* 控制图片不重复 */
						background-size: cover;
						/* 调整图片大小以适应div尺寸 */
						/* 可选：以下属性用于对齐和定位图片 */
						background-position: center center;
						/* 居中对齐 */
					}
				}

				.business-partner {
					display: flex;
					width: 164px;
					height: 80px;
					flex-shrink: 0;
					border-radius: 4px;
					background: #FFF;
					box-shadow: 0px 2px 9px 0px rgba(0, 0, 0, 0.06);
					padding-top: 20px;
					padding-left: 16px;

					.partner-img {
						height: 108rpx;
						width: 108rpx;
						margin-left: 12px;
						border-radius: 100% 100% 100% 100%;
						background-image: url("@/xj_distribution/static/distributionPartner.png");
						background-repeat: no-repeat;
						/* 控制图片不重复 */
						background-size: cover;
						/* 调整图片大小以适应div尺寸 */
						/* 可选：以下属性用于对齐和定位图片 */
						background-position: center center;
						/* 居中对齐 */
					}
				}

				.business-goods {
					margin-top: 48rpx;
					position: relative;
					color: #FFF;
					height: 62px;
					flex-shrink: 0;
					border-radius: 12px;
					background: #333;

					.goods-promotion {
						position: absolute;
						top: 6px;
						left: 143px;
						color: #FFF;
						font-family: YouSheBiaoTiHei;
						font-size: 22px;
						font-style: normal;
						font-weight: 400;
						line-height: normal;
						letter-spacing: 5px;
					}

					.goods-brokerage {
						position: absolute;
						top: 35px;
						left: 143px;
						color: #FFF;
						font-family: Noto Sans SC;
						font-size: 12px;
						font-style: normal;
						font-weight: 700;
						line-height: 20px;
						/* 166.667% */
						letter-spacing: 1px;
					}

					.goods-go {
						position: absolute;
						top: 19px;
						left: 266px;
						display: flex;
						width: 53px;
						height: 25px;
						padding: 6px 7px;
						justify-content: center;
						align-items: center;
						gap: 10px;
						flex-shrink: 0;
						border-radius: 28px;
						background: #F65D07;
						color: #FFF;
						font-family: Noto Sans SC;
						font-size: 16px;
						font-style: normal;
						font-weight: 700;
						line-height: 20px;
						/* 125% */
						letter-spacing: 1px;
					}
				}
			}

			.body-data {
				display: flex;
				flex-direction: column;
				margin-left: 32rpx;
				margin-right: 32rpx;
				height: 218rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 4rpx 18rpx rgba(0, 0, 0, 0.06);
				border-radius: 8rpx;
				margin-top: 24rpx;

				.data-head {
					display: flex;
					justify-content: space-between;
					margin-top: 26rpx;
					margin-left: 32rpx;
					margin-right: 32rpx;
				}

				.data-menu {
					display: flex;
					justify-content: space-between;
					margin-left: 78rpx;
					margin-right: 78rpx;
					padding-top: 62rpx;
					font-size: 24rpx;
				}
			}
		}
	}

	#distributionPs {
		margin-top: -36px;
	}

	#distributionMoney {
		margin-top: -6px;
		margin-left: -40px;
	}
</style>